<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<style>
			span.DataTables_sort_icon.css_right.ui-icon.ui-icon-carat-2-n-s{display:none;}
	</style>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<script type="text/javascript">
		var aJaxURL = "server-side/operations/payments.action.php";			//server side folder url
		var seoyURL = "server-side/seoy/seoy.action.php";	    			//server side folder url
		var tName 	= "pos-table";											//table name
		var fName 	= "pos-form";    
		var sale    = 0;                          			    //form name							
		var menuLength = [[100], [100]];
		var dialogButton = {
	        "save": {
	            text: "არჩევა",
	            id: "save-pos-select",
	            click: function () {
	            }
	        }
	    };
		var oID		= 0;
		
		$(document).ready(function (){
			AjaxSetup1();
			SelectPOS();
			GetDialog("pos-select-form", 480, "auto", dialogButton);
			
	
			
			
	//		SeoY("seoy-input", seoyURL, "pos", "status="+status, 1);
			
			
			$("#navigate").hide();
			$("#pos-wrapper").hide();
			
			$("#seoy_button").button({
	            icons: {
	                primary: "ui-icon-check"
	            }
        	});
        	
			$("#save_button").button({
	            icons: {
	                primary: "ui-icon-disk"
	            }
        	});
        	
			$("#cancel_button").button({
	            icons: {
	                primary: "ui-icon-closethick"
	            }
        	});

			$("#print_button").button({
	            icons: {
	                primary: "ui-icon-print"
	            }
           
        	});

			$("#pay_button").button({
	            icons: {
	                primary: "ui-icon-check"
	            }
           
        	});

			$("#terminal_payment").button({
	            icons: {
	                primary: "ui-icon-calculator"
	            }
        	});

			$("#add_money").button({
	            icons: {
	                primary: "ui-icon-circle-plus"
	            }
        	});

			$("#take_money").button({
	            icons: {
	                primary: "ui-icon-circle-minus"
	            }
        	});
        	    	
			$("#add_payment").button({
	            icons: {
	                primary: "ui-icon-check"
	            }
        	});

			GetMainMenu();
			GetTransactions();
			//on number change send requests to get auto number history
		
// 			$("#auto_number").keyboard({

// 				 display: {
// 				  'bksp'   : '\u2190',
// 				  'enter'  : 'return',
// 				  'default': 'ABC',
// 				  'accept' : '\u21d3'
// 				 },

// 				 layout: 'custom',

// 				 customLayout: {

// 				  'default': [
// 				   'Q W E R T Y U I O P {sp:1} 7 8 9 {bksp}',
// 				   'A S D F G H J K L {sp:1} {sp:1} 4 5 6 -',
// 				   'Z X C V B N M {sp:1} {sp:1} {accept} {sp:1} 1 2 3 0'
// 				  ]
// 				 }
				 

// 			});
			
// 			$("#quantity").keyboard({

// 				 display: {
// 				  'bksp'   : '\u2190',
// 				  'enter'  : 'return',
// 				  'default': 'ABC',
// 				  'accept' : '\u21d3'
// 				 },

// 				 layout: 'custom',

// 				 customLayout: {

// 				  'default': [
// 				   '1 2 3',
// 				   '4 5 6',
// 				   '7 8 9',
// 				   '0 {bksp} {accept}'
// 				  ]
// 				 }

// 			});



		});



		function SelectPOS(){

        	
			$.ajax({
				url: aJaxURL,
				data: "act=select_pos",       
				success: function(data) {
					if (typeof (data.error) != "undefined") {
                        if (data.error != "") {
                            alert(data.error);
                        } else {
                        	$("#pos-select-form").html(data.page);
                        	
                			$("#dont-confirm-pos").button({
                        	});	
                			$("#dont-confirm-pos").click(function(){
                    			
                				$("#check-failed").css("visibility","visible");
                			});
                        }
                    }
				}
			});
		}
		
		function LoadDialog(){		
		    $("#" + fName).dialog({
		        resizable:     false,
		        draggable:     false,		       
		        width:         1337,
		        height:        900,
		        modal:         false,
		        stack:         true,
                sticky:        false,
                closeOnEscape: false,
                dialogClass:   "pos-dialog"
		    });
		}
		
		function LoadTable(){
			/* Table ID, aJaxURL, Action, Colum Number, Custom Request, Hidden Colum, Menu Array */
			GetDataTable(tName, aJaxURL, "get_list", 5, "obj_id=" + oID, 0, menuLength, 0, "asc");					
		}


		$(document).on("click", "#save-pos-select", function() {		
			oID		= $("#obj_id :selected").val();
			oName	= $("#obj_id :selected").text();
			$("#" + fName).attr("title", oName);
			
			
			LoadDialog();
			LoadTable();
			
			GetQuantity(oID);
			GetSumPrice(oID);
			
			$("#pos-wrapper").fadeIn("slow");
			$("#seoy-input").focus();
			$("#pos-select-form").dialog("close");
			GetTransactions2();
			SetEvents("", "", "", "pos-table", fName, aJaxURL);

			if($("#pos_money_amount").val()){
				var obj_id = oID;
				var money_amount  = $("#pos_money_amount").val();
				var comment       = $("#reason").val();
				var money         = $("#pos-money").text();
				
				$.ajax({
					url: aJaxURL,
					data: "act=pos-check&obj_id=" + obj_id + "&money-amount=" + money_amount + "&comment=" + comment,
					success: function(data) {
						if (typeof (data.error) != "undefined") {
	                        if (data.error != "") {
	                            alert(data.error);
	                        } else { 
	                        	PrintSalary(obj_id, money);
	                        }
	                    }
					}
				});
				
			}
		});

		$(document).on("click", "#save_button", function() {	
			var obj_id	= oID;
		
			
			if(parseInt($('#pos-table tbody tr td').children().length) === 0){ 
				alert("პროდუქციის სია ცარიელია!");
				
			}else{
				$.ajax({
					url: aJaxURL,
					data: "act=save_transaction&obj_id=" + obj_id,
					success: function(data) {
						if (typeof (data.error) != "undefined") {
	                        if (data.error != "") {
	                            alert(data.error);
	                        } else {
	    						GetQuantity(obj_id);
	    						GetSumPrice(obj_id);
	    						LoadTable();
	    						GetTransactions2();
	    						GetMainMenu();
	                        }
	                    }
					}
				});
			}
		});

		$(document).on("click", "#cancel_button", function() {
			var obj_id	= oID;
			var col =  parseInt($("tr.odd").text());

			
			if(!isNaN(col)){
				$.ajax({
					url: aJaxURL,
					data: "act=abort_transaction&obj_id=" + obj_id,        
					success: function(data) {
						if (typeof (data.error) != "undefined") {
	                        if (data.error != "") {
	                            alert(data.error);
	                        } else {
	    						GetQuantity(obj_id);
	    						GetSumPrice(obj_id);						
	    						LoadTable();
	    						GetTransactions2();
	                        }
	                    }
					}
				});  
			}      
			});

		$(document).on("click", ".pos-prod-delete", function() {
			var trans_id  = $(this).text();
			var obj_id	= oID;
			
			$.ajax({
				url: aJaxURL,
				data: "act=delete_prod&trans_id=" + trans_id + "&obj_id=" + obj_id,        
				success: function(data) {
					if (typeof (data.error) != "undefined") {
                        if (data.error != "") {
                            alert(data.error);
                        } else {
    						GetQuantity(obj_id);
    						GetSumPrice(obj_id);
    						LoadTable();
                        }
                    }
				}
			});
		});


		$(document).on("click", "#price_change_button", function() {
			var obj_id	= oID;	
			 param 			= new Object();

			 param.act	            = "save_vew_price";	
			 param.prod_new_price	= $("#prod_new_price").val();
			 param.prod_new_count	= $("#prod_new_count").val();
			 param.id   = sale;
		
			
			
				$.ajax({
					url: aJaxURL,
					data: param,
					success: function(data) {
						if (typeof (data.error) != "undefined") {
	                        if (data.error != "") {
	                            alert(data.error);
	                        } else {
	                        	CloseDialog("price_change");
	    						GetQuantity(obj_id);
	    						GetSumPrice(obj_id);
	    						LoadTable();
	    						GetTransactions2();
	    						GetMainMenu();
	    						
	    						
	                        }
	                    }
					}
				});
			
		});
		
	$(document).on("keypress", "#sum-total-price2", function(e) {

			if(e.which == 13){		
				MakePayment();
			}
	});
		1

	$(document).on("click", "#add_payment", function() {		
			
					MakePayment();		
					
	});


	$(document).on("click", "#add_money", function() {	
			var obj_id	= oID;

			
			$.ajax({
				url: aJaxURL,
				data: "act=add-money-page&obj_id=" + obj_id,       
				success: function(data) {
					if (data.error != "") {
                        alert(data.error);
                    } else {
	                	$("#money_transfer").html(data.page);
                    }
				}
			});
	
			
			var button = {
			        "save": {
			            text: "დამატება",
			            id: "add_money_salary",
			            click: function () {
			            }
			        },	
			        "cancel": {
			            text: "დახურვა",
			            id: "cancel-dialog",
			            click: function () {
			                $(this).dialog("close");
			            }
			        }
			    };
			GetDialog("money_transfer", 541, "auto", button);			
	});

	//-----------------------------------------------------//

	$(document).on("click", ".pos-prod-change", function() {
		
		
		 param 			= new Object();

		 param.act	= "get_edit_page";
		 sale =	$(this).text();
		 param.id   = sale;

		
		$.ajax({
			url: aJaxURL,
			data: param,       
			success: function(data) {
				if (data.error != "") {
                    alert(data.error);
                } else {
                	$("#price_change").html(data.page);
                }
			}
		});

		
		var button = {
		        "save": {
		            text: "შენახვა",
		            id: "price_change_button",
		            click: function () {
		            }
		        },	
		        "cancel": {
		            text: "დახურვა",
		            id: "cancel-dialog",
		            click: function () {
		                $(this).dialog("close");
		            }
		        }
		    };
		GetDialog("price_change", 400, "auto", button);			
});

	$(document).on("click", "#add_money_salary", function() {	
				var obj_id       =  oID;	
				var money_amount =  parseFloat($("#money-amount").val());
				var comment      =  $("#notice").val();
				var username     =  $("#username").val();
				var password     =  $("#password").val();

				if(confirm("დარწმუნებული ხართ?")){
					$.ajax({
						url: aJaxURL,
						data: "act=add-money&obj_id=" + obj_id + "&money-amount=" + money_amount + "&comment=" + comment + "&username=" + username + "&password=" + password,       
						success: function(data) {
							if (data.error != "") {
		                        alert(data.error);
		                    } else {
		                    	$("#money_transfer").dialog("close");
		                    }
						}
					});
				}
				
	});

	$(document).on("click", "#take_money", function() {	
			var obj_id	= oID;

			
			$.ajax({
				url: aJaxURL,
				data: "act=take-money-page&obj_id=" + obj_id,       
				success: function(data) {
					if (data.error != "") {
                        alert(data.error);
                    } else {
	                	$("#money_transfer").html(data.page);
                    }
				}
			});
	
			
			var button = {
			        "save": {
			            text: "გატანა",
			            id: "take_money_salary",
			            click: function () {
			            	 
			            }
			        },	
			        "cancel": {
			            text: "დახურვა",
			            id: "cancel-dialog",
			            click: function () {
			                $(this).dialog("close");
			            }
			        }
			    };
			GetDialog("money_transfer", 541, "auto", button);

	});		
		
	$(document).on("click", "#take_money_salary", function() {	
			var obj_id       =  oID;	
			var money_amount =  parseFloat($("#take-money-amount").val());
			var comment      =  $("#take-notice").val();
			var username     =  $("#username").val();
			var password     =  $("#password").val();

			if(confirm("დარწმუნებული ხართ?")){
				$.ajax({
					url: aJaxURL,
					data: "act=take-money&obj_id=" + obj_id + "&money-amount=" + money_amount + "&comment=" + comment + "&username=" + username + "&password=" + password,       
					success: function(data) {
						if (data.error != "") {
	                        alert(data.error);
	                    } else {
	                    	$("#money_transfer").dialog("close");
	                    }
					}
				});
			}
			
	});
				

		$(document).on("click", "#terminal_payment", function() {		
			
			var sum			= parseFloat($("#sum-price").text());
			var total_sum	= parseFloat($("#sum-total-price3").val());
		//	var trans_id 	= parseFloat($("#transact_id").html());
			var pay_type    = 2;


			$("#auto_number").val("");

			if(confirm("დარწმუნებული ხართ, რომ გსურთ გადახდა?")){
					
						var obj_id	= oID;
										
						$.ajax({
							url: aJaxURL,
							data: "act=payment_done&obj_id=" + obj_id + "&payed_money=" + total_sum + "&pay_type=" + pay_type,        
							success: function(data) {
								if (typeof (data.error) != "undefined") {
			                        if (data.error != "") {
			                            alert(data.error);
			                        } else {
										GetQuantity(obj_id);
										GetSumPrice(obj_id);
										LoadTable();
										$("#sale_price").val(0);
										$("#seoy-input").val("");
										$("#change2").val("0.00");
									//	$('#pos-payment-form').dialog('close');
										GetTransactions2();	
			                        }
			                    }
							}
						 });
					
			}
			
		});

		$(document).on("click", "#pay_button", function() {		
			
			var sum			= parseFloat($("#sum-price").text());
			var total_sum	= parseFloat($("#sum-total-price3").val());
		//	var trans_id 	= parseFloat($("#transact_id").html());
			var pay_type    = 1;

			$("#auto_number").val("");

			if(confirm("დარწმუნებული ხართ, რომ გსურთ გადახდა?")){
					
						var obj_id	= oID;							
						$.ajax({
							url: aJaxURL,
							data: "act=payment_done&obj_id=" + obj_id + "&payed_money=" + total_sum + "&pay_type=" + pay_type,        
							success: function(data) {
								if (typeof (data.error) != "undefined") {
			                        if (data.error != "") {
			                            alert(data.error);
			                        } else {
										GetQuantity(obj_id);
										GetSumPrice(obj_id);
										LoadTable();
										$("#sale_price").val(0);
										$("#seoy-input").val("");
										$("#change2").val("0.00");
										printCheck(sum);
									//	$('#pos-payment-form').dialog('close');
										GetTransactions2();	
			                        }
			                    }
							}
						 });
				
			}
			
		});

		$(document).on("keyup", "#sum-total-price2", function() {
		    var val = $(this).val();
		    if(isNaN(val)){
		         val = val.replace(/[^0-9\.]/g,'');
		         if(val.split('.').length>2) 
		             val =val.replace(/\.+$/,"");
		    }
		    $(this).val(val); 
		    
			var change = parseFloat((parseFloat($("#sum-total-price2").val()) - parseFloat($("#sum-price2").text()))).toFixed(2);
			if(change > 0){
				$("#change").text(change);
				}else{
					$("#change").text("0.00");
			}
			
		});

		$(document).on("keyup", "#sum-total-price3", function() {
		    var val = $(this).val();
		    if(isNaN(val)){
		         val = val.replace(/[^0-9\.]/g,'');
		         if(val.split('.').length>2) 
		             val =val.replace(/\.+$/,"");
		    }
		    $(this).val(val); 
		    var z = parseInt($("#sum-price").text());
		    
			var change = parseFloat((parseFloat($("#sum-total-price3").val()) - parseFloat($("#sum-price").text()))).toFixed(2);
			if(change > 0 && z !== 0){
				$("#change2").text(change);
			}else{
				$("#change2").text("0.00");
			}
			
		});

		/* დიალოგით გადახდა
		$(document).on("click", ".restore_suspend_button", function() {
			var obj_id	= oID;
			var trans_id = $(this).attr("trans");
					
			$("#trans_id_hidden").val(trans_id);	
			if(parseInt($('#pos-table tbody tr td').children().length) !== 0){ 
				alert("აქტიურია სხვა ტრანზაქცია! \n * შეამოწმეთ პროდუქტების სია");
			}else{
					$.ajax({
					url: aJaxURL,
					data: "act=restore_suspended&obj_id=" + obj_id + "&trans_id=" + trans_id,       
					success: function(data) {
						if (data.error != "") {
	                        alert(data.error);
	                    } else {
							GetTransactions2();
							GetQuantity2(obj_id);
							GetSumPrice2(obj_id, trans_id);
	 						$("#pos-payment-form").html(data.page);	
	 						$("#add_payment").button({
	 				            icons: {
	 				                primary: "ui-icon-check"
	 				            }
	 			        	});
	 							
	                    }
					}
				});
			

			var button = {
			        "cancel": {
			            text: "დახურვა",
			            id: "suspend-dialog",
			            click: function () {
			    				$(this).dialog('close');
			            }
			        }
			    };
				GetDialogPay("pos-payment-form", 300, "auto", button);
			}
		});
		*/
		function GetMainMenu(){
			$.ajax({
				url: aJaxURL,
				data: "act=get_main_menu",     
				success: function(data) {
					if (typeof (data.error) != "undefined") {
                        if (data.error != "") {
                            alert(data.error);
                        } else {
                        	$("#main_menu").html(data.page);	
                        }
                    }
				}
			});
		}
		
		$(document).on("click", ".main", function() {
			var id = $(this).attr("id");

			$.ajax({				
				url: aJaxURL,
				data: "act=get_sub_menu&id=" + id,      
				success: function(data) {
					if (typeof (data.error) != "undefined") {
                        if (data.error != "") {
                            alert(data.error);
                        } else {
                        	$("#main_menu").html(data.page);        	
                        }
                    }
				}
			});
			
		});

		$(document).on("click", ".restore_suspend_button_restore", function() {
		var obj_id	= oID;
		var trans_id = $(this).attr("trans");
		
		$("#trans_id_hidden").val(trans_id);	
		if(parseInt($('#pos-table tbody tr td').children().length) !== 0){ 
			alert("აქტიურია სხვა ტრანზაქცია! \n * შეამოწმეთ პროდუქტების სია");
		}else{
			    $.ajax({
				url: aJaxURL,
				data: "act=restore_suspended_restore&obj_id=" + obj_id + "&trans_id=" + trans_id,      
				success: function(data) {
					if (data.error != "") {
                       alert(data.error);
					} else {
						GetTransactions2();
						LoadTable();
						GetQuantity(oID);
						GetSumPrice(oID);
						$("#transact_id").html(trans_id);
						$("#auto_number").val(data.page);
                   }
				}
			});
		}
		
	});
		
		
// 		$(document).on("click", ".cancel_suspend_button", function() {
// 			var obj_id	= oID;
// 			var trans_id = $(this).attr("trans");

// 			if(confirm("დარწმუნებული ხართ რომ გსურთ ტრანზაქციის წაშლა?")){
// 				$.ajax({
// 					url: aJaxURL,
// 					data: "act=cancel_suspend&trans_id=" + trans_id,       
// 					success: function(data) {
// 						if (data.error != "") {
// 	                        alert(data.error);
// 						} else {
// 							GetTransactions();
// 	                    }
// 					}
// 				});
// 			}
// 		});
		
		function GetMainMenu(){
			$.ajax({
				url: aJaxURL,
				data: "act=get_main_menu",     
				success: function(data) {
					if (typeof (data.error) != "undefined") {
                        if (data.error != "") {
                            alert(data.error);
                        } else {
                        	$("#main_menu").html(data.page);	
                        }
                    }
				}
			});
		}
		
		
		//click on production
		
		$(document).on("click", ".productions", function() {	
			var obj_id	= oID;
			var prod_id = $(this).attr("id");
			
			$.ajax({
				url: aJaxURL,
				data: "act=prod_ing_page&obj_id=" + obj_id + "&prod_id=" + prod_id,       
				success: function(data) {
					if (data.error != "") {
                        alert(data.error);
                    } else {
	                	$("#pos-production-form").html(data.page);
	                	RecipieSpinner();
                    }
				}
			});
			

			
			
			var button = {
		        "save": {
		            text: "დამატება",
		            id: "save-dialog",
		            click: function () {
		            }
		        },	
		        "cancel": {
		            text: "დახურვა",
		            id: "cancel-dialog",
		            click: function () {
		                $(this).dialog("close");
		            }
		        }
		    };
		    
			GetDialog("pos-production-form", 541, "auto", button);

	});	

	// click on name
	 $(document).on("click", ".production_name", function() {	
			var obj_id	= oID;
			var prod_id = $(this).attr("id");
			
			$.ajax({
				url: aJaxURL,
				data: "act=prod_ing_page&obj_id=" + obj_id + "&prod_id=" + prod_id,       
				success: function(data) {
					if (data.error != "") {
                        alert(data.error);
                    } else {
	                	$("#pos-production-form").html(data.page);
	                	RecipieSpinner();
                    }
				}
			});
			

			
			
			var button = {
		        "save": {
		            text: "დამატება",
		            id: "save-dialog",
		            click: function () {
		            }
		        },	
		        "cancel": {
		            text: "დახურვა",
		            id: "cancel-dialog",
		            click: function () {
		                $(this).dialog("close");
		            }
		        }
		    };
		    
			GetDialog("pos-production-form", 541, "auto", button);
	});	
		
	//click on price
		
	 $(document).on("click", ".production_price", function() {	
			var obj_id	= oID;
			var prod_id = $(this).attr("id");
			
			$.ajax({
				url: aJaxURL,
				data: "act=prod_ing_page&obj_id=" + obj_id + "&prod_id=" + prod_id,       
				success: function(data) {
					if (data.error != "") {
                  alert(data.error);
              } else {
	                	$("#pos-production-form").html(data.page);
	                	RecipieSpinner();
              }
				}
			});
			

			
			
			var button = {
		        "save": {
		            text: "დამატება",
		            id: "save-dialog",
		            click: function () {
		            }
		        },	
		        "cancel": {
		            text: "დახურვა",
		            id: "cancel-dialog",
		            click: function () {
		                $(this).dialog("close");
		            }
		        }
		    };
		    
			GetDialog("pos-production-form", 541, "auto", button);

	});				
		// save button
	    $(document).on("click", "#save-dialog", function () {
		    	param = new Object();	    	
	            //Action
		    	obId	= $("#obj_id :selected").val();
		    	
		    	param.act			= "add_prod";		

		    	param.obj_id		= $("#obj_id :selected").val();
			    param.id         	= $("#prod_id").html();
			   	param.quantity		= $("#prod_quantity").val();
// 			   	param.car_number	= $("#auto_number").val();
			   	param.price			= 0;
				
			   	/*  ARRAY OF PRODUCTION */
			    var array = new Array();
			    
			
		    	$("tr.trCheckClass1").each(function(){
					$this = $(this)
				    var value = $this.find("span.id_value").html();				    
		    		array.push(Array($("#type_"+value).text(), $("#quantity_"+value).val(), $("#ingr_quantity_"+value).val()));
		    	});
		    	param.list	= JSON.stringify(array);
				var checkedArray = myEmptyArray(array);
				
				if(!checkedArray && !empty(array)){
					GetAlertDialog("no-ingredients");
				}else {
						
				    $.ajax({
				        url: aJaxURL,
					    data: param,
				        success: function(data) {
							if(typeof(data.error) != "undefined")
							{
								if(data.error != "")
								{
									alert(data.error);
								}else
								{
									GetQuantity(obId);
									GetSumPrice(obId);
									LoadTable("pos-container-table");
					        		CloseDialog("pos-production-form");					        		
								}
							}
					    }
				    });
				}
			});

		

		$(document).on("click", "#backTop", function() {
			GetMainMenu();		
		});

		function GetQuantity(obj_id){
			$.ajax({
				url: aJaxURL,
				data: "act=get_prod_count&obj_id=" + obj_id,        
				success: function(data) {
					if (typeof (data.error) != "undefined") {
                        if (data.error != "") {
                            alert(data.error);
                        } else {
                            if(empty(data.prod_count))
                        		$("#prod-quantity").text(0);
                            else
                        		$("#prod-quantity").text(data.prod_count);
                        }
                    }
				}
			});
		}		
				
		function GetSumPrice(obj_id){
			$.ajax({
				url: aJaxURL,
				data: "act=get_sum_price&obj_id=" + obj_id,        
				success: function(data) {
					if (typeof (data.error) != "undefined") {
                        if (data.error != "") {
                            alert(data.error);
                        } else {
                            if(empty(data.sum_price)){
        						$("#sum-price").text("00.00");
        						$("#sum-total-price").val("00.00");
        						$("#sum-total-price3").val("00.00");
        						$("#change2").html("0.00");
                            } else{
        						$("#sum-price").text(data.sum_price);
        						$("#sum-total-price").val(data.sum_price);
        						$("#sum-total-price3").val(data.sum_price);
                            }
                        }
                    }
				}
			});
		}

		function GetQuantity2(obj_id){
			$.ajax({
				url: aJaxURL,
				data: "act=get_prod_count_2&obj_id=" + obj_id,        
				success: function(data) {
					if (typeof (data.error) != "undefined") {
                        if (data.error != "") {
                            alert(data.error);
                        } else {
                            if(empty(data.prod_count))
                        		$("#prod-quantity2").text(0);
                            else
                        		$("#prod-quantity2").text(data.prod_count);
                        }
                    }
				}
			});
		}		
				
		function GetSumPrice2(obj_id, trans_id){
			$.ajax({
				url: aJaxURL,
				data: "act=get_sum_price_2&obj_id=" + obj_id + "&trans_id=" + trans_id,        
				success: function(data) {
					if (typeof (data.error) != "undefined") {
                        if (data.error != "") {
                            alert(data.error);
                        } else {
                            if(empty(data.sum_price)){
        						$("#sum-price2").text("00.00");
        						$("#sum-total-price2").val("00.00");
                            } else{
        						$("#sum-price2").text(data.sum_price);
        						$("#sum-total-price2").val(data.sum_price);
        						$("#sum-total-price2").select();
                            }
                        }
                    }
				}
			});
		}

		function myEmptyArray(array) {
		    for(var i = 0; i < array.length; i++) {
		        if(array[i][1] != 0) {
		            return true;
		        }
		    }
		    return false;
		}

		$(document).on("click", "#print_button", function () {
	    	param = new Object();
	    	
            //Action
		    param.id	 = $("#obj_id :selected").val();
		    param.status = 1;
	    	var link = $(this).attr("str");
	    	link = "server-side/print/print.action.php?id=" + param.id + "&status=" + param.status;
	    	
	    	var newWin = window.open(link, "JSSite", "width=800,height=800,resizable=yes,scrollbars=yes,status=yes");
	    	newWin.focus();
	    	newWin.onload = function() {
	    		newWin.print();
	    		setInterval(function(){newWin.close()},500);
		    }
	    });

		function GetTransactions(){
			var obj_id	= oID;
			
			$.ajax({
				url: aJaxURL,
				data: "act=suspended_page&obj_id=" + obj_id,       
				success: function(data) {
					if (data.error != "") {
	                    alert(data.error);
	                } else {
	                	$("#pos-transactions-form").html(data.page);
	          			$( ".restore_suspend_button" ).button({
	        			      icons: {
	        			        primary: "ui-icon-circle-check"
	        			      }
	        			});
	          			$( ".restore_suspend_button_restore" ).button({
	        			      icons: {
	        			        primary: "ui-icon-arrowreturnthick-1-w"
	        			      }
	        			});
	                }
				}
			}).done(function(data) { 
                setTimeout(GetTransactions, 2000);
            });
		}

		function GetTransactions2(){
			var obj_id	= oID;
			
			$.ajax({
				url: aJaxURL,
				data: "act=suspended_page&obj_id=" + obj_id,       
				success: function(data) {
					if (data.error != "") {
	                    alert(data.error);
	                } else {
	                	$("#pos-transactions-form").html(data.page);
	          			$( ".restore_suspend_button" ).button({
	        			      icons: {
	        			        primary: "ui-icon-circle-check"
	        			      }
	        			});
	          			$( ".restore_suspend_button_restore" ).button({
	        			      icons: {
	        			        primary: "ui-icon-arrowreturnthick-1-w"
	        			      }
	        			});
	                }
				}
			});
		}
		
		/*
		function GetDialogPay(fname, width, height, buttons) {

		    $("#" + fname).dialog({
		    	position:"center",
		        resizable: false,
		        width: width,
		        height: height,
		        modal: true,
		        stack: false,
		        closeOnEscape: false,
		        dialogClass: fname + "-class",
		        buttons: buttons,
		        open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); }
		    });

		}
		*/
		
		

		function GetAlertDialog(fname) {
			var button = {
			        "cancel": {
			            text: "დახურვა",
			            id: "cancel-dialog",
			            click: function () {
			                $(this).dialog("close");
			            }
			        }
			}	
			
		    $("#" + fname).dialog({
		    	position:"center",
		        resizable: false,
		        width: 230,
		        height: "auto",
		        modal: false,
		        stack: false,
		        closeOnEscape: false,
		        dialogClass: fname + "-class",
		        buttons: button,
		        open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); }
		    });
		}

		function GetConfirmDialog(fname, button){


				    $("#" + fname).dialog({
				    	position:"center",
				        resizable: false,
				        width: 250,
				        height: "auto",
				        modal: true,
				        stack: false,
				        closeOnEscape: false,
				        dialogClass: fname + "-class",
				        buttons: button,
				        open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); }
				    });
			        
		}

		
		function RecipieSpinner(){
	       	 $("tr.trCheckClass1").each(function() {
				 $this	   = $(this);
				 var value = $this.find("span.id_value").html();

				  if(($("#ingr_quantity_"+value).val()) ==  0){
						 $("#quantity_" + value).val(0);
				  }
					
				  $("#increment_" + value).click(function(){ 

						$("#quantity_" + value).val(parseFloat($("#ingr_quantity_" + value).val() *  $("#id_quantity_" + value).val()*100/100).toFixed(3));
						
						 
				   });
				 
				  $("#decrement_" + value).click(function(){ 
						
						if( $("#ingr_quantity_" + value).val() !=0 ){
							$("#quantity_" + value).val(parseFloat($("#ingr_quantity_" + value).val() *  $("#id_quantity_" + value).val()*100/100).toFixed(3));
							} else {		
						     $("#quantity_" + value).val(0);
							}									
						 }); 
				 							 
				});
		}

		function MakePayment(){
			var sum			= parseFloat($("#sum-price2").text());
			var total_sum	= parseFloat($("#sum-total-price2").val());
			//var trans_id 	= $("#add_payment").attr("trans");	
			var pay_type    = 1;
			
			$("#auto_number").val("");
			
			if(confirm("დარწმუნებული ხართ, რომ გსურთ გადახდა?")){
					
						var obj_id	= oID;
										
						$.ajax({
							url: aJaxURL,
							data: "act=payment_done&obj_id=" + obj_id + "&payed_money=" + total_sum + "&pay_type=" + pay_type,        
							success: function(data) {
								if (typeof (data.error) != "undefined") {
			                        if (data.error != "") {
			                            alert(data.error);
			                        } else {
										GetQuantity(obj_id);
										GetSumPrice(obj_id);
										LoadTable();
										$("#sale_price").val(0);
										$("#seoy-input").val("");
										printCheck(sum);
									//	$('#pos-payment-form').dialog('close');
										GetTransactions2();	
			                        }
			                    }
							}
						 });
				
			}
		}		
////////////////////////

		$(document).on("keypress", "#seoy-input", function() {
			status = $("input[name='search_type']:checked").val();
			SeoY("seoy-input", seoyURL, "pos", "status="+status, 1);
			if ( event.which == 13 ) {
				
				$("#seoy_button").click();
				$("#seoy-input").autocomplete("close");
				$("#seoy-input").val("");
			}
		});

		$(document).on("click", "#seoy_button", function() {
			param = new Object();
			
            //Action
            param.act	= "add_prod_seo";
            
            param.name		= $("#seoy-input").val();
            param.obj_id	= oID;
            param.trans_id 	= $("#trans_id_hidden").val();	
            //param.price		= $("#sale_price").val();
			
			$.ajax({
				url: aJaxURL,
				data: param,
				success: function(data) {
					if (typeof (data.error) != "undefined") {
                        if (data.error != "") {
                            alert(data.error);
                        } else {
    						GetQuantity(param.obj_id);
    						GetSumPrice(param.obj_id);
    						LoadTable();
    						//$("#sale_price").val(0);
    						//$("#seoy-input").val("");
                        }
                    }
				}
			});
		});

		function PrintSalary(obj_id, money){
	    	param = new Object();
	    	
            //Action
		    param.id	 = obj_id;
		    param.money  = money;

	    	var link = $(this).attr("str");
	    	link = "server-side/print/print_salary.php?id=" + param.id + "&money=" + money;
	    	
	    	var newWin = window.open(link, "JSSite", "width=800,height=800,resizable=yes,scrollbars=yes,status=yes");
	    	newWin.focus();
	    	newWin.onload = function() {
	    		newWin.print();
	    		setInterval(function(){newWin.close()},500);
		    }
		}

		$(document).on("keyup", "#money-amount, #take-money-amount, #pos_money_amount", function() {
		    var val = $(this).val();
		    if(isNaN(val)){
		    	alert("მოცემულ ველში შეიყვანეთ მხოლოდ ციფრები");
		         val = val.replace(/[^0-9\.]/g,'');
		         if(val.split('.').length>2) 
		             val =val.replace(/\.+$/,"");
		    }
		    $(this).val(val); 
		});
	</script>
	
	<style type="text/css">
		.dataTable_buttons{
			display: none;
		}
	</style>
</head>
<body onselectstart='return false;' ondragstart='return false';>
	<a  style="display: none;" id="bt1" href="media/print/DEFEXEC.txt" download>link</a>
	<div id="pos-wrapper">
	    <!-- jQuery Dialog -->
	    <div id="pos-select-form" class="form-dialog" title="სალაროს არჩევა">
	    </div>
	    
	    <!-- jQuery Dialog -->
	    <div id="pos-payment-form" class="form-dialog" title="გადახდა">
	    </div>    
	    
	     <!-- jQuery Dialog -->
	    <div id="pos-production-form" class="form-dialog" title="პროდუქტი">
	    </div>
	    
	    <!-- jQuery Dialog -->
	    <div id="money_transfer" class="form-dialog" title="თანხის მოძრაობა">
	    </div> 
	      <!-- jQuery Dialog -->
	    <div id="price_change" class="form-dialog" title="რედაქტირება">
	    </div>   
	    
	 	    
	    <!-- jQuery Dialog -->
	    <div id="no-ingredients" class="form-dialog" title="ინფო" style="text-align:center;"> ინგრედიენტები არ არის!
	    </div>  
	   	    	   
	    <div id="pos-form" style="overflow:hidden">
	    	<table id="pos-container-table">
				<tr>
					<td style="width:480px !important; height:515px !important;">
						<div id="product-wrapper" class="fg-toolbar ui-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix"">
							<div id="pos-seoy">
					           	<input id="seoy-input" type="text" name="seoy-input">
					           	 <span style=" display: inline-block; margin: 3px 0 0 0;"><input  style="float: left;" type="radio" name="search_type" value="1" checked>შიდა კოდით</span>
					           	 <br>
					             <span style=" display: inline-block;"><input style="float: left;" type="radio" name="search_type" value="2" >შტრიხ კოდით</span>
								 <br>
					           	 <span style=" display: inline-block;"><input style="float: left;" type="radio" name="search_type" value="3" >სახელით</span>
								<button id="seoy_button" style="padding: 12px 1px; margin: -22px 10px;"><span style="display:none;">დ</span></button>
							</div>
						
							 <div class="pos-inner-table">
							    <div id="dt_example" class="ex_highlight_row">
						            <div id="dynamic">
						                <table class="display" id="pos-table">
						                    <thead>
						                        <tr id="datatable_header">
						                   			<th>ID</th>
						                            <th width="100%">დასახელება</th>
						                            <th width="50px">რაოდ.</th>
						                            <th width="70px">ფასი</th>
						                            <th width="70px">ჯამი</th>
						                            <th style="width: 60px"; class="check"></th>
						                         </tr>
						                    </thead>
						                </table>
						            </div>
						    	</div>
						    </div>
						</div>
						<div class="fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix" id="pos-table-footer"></div>
					</td>
					<td rowspan="2" width="8">&nbsp;</td>	
					<td rowspan="2" width="5">
						<div id="main-menu-container" style="width: 460px; height:605px; position:relative; overflow-x: scroll;"> 
							<table id="main_menu" style="width: 428px;" class="tableClass">							
							</table>
						</div>							
					</td>
					<td rowspan="2">
					<table>		
							<tr>
	 							<td>
									<div id="pos-transactions-form"  title="შეჩერებული ტრანზაქციები" style="margin-left:10px; border-top:6px ridge; padding:10px;"> 
								    </div>
								</td>				
							</tr>							
							<tr>
	 							<td>
									<div style="margin-left:10px; border-top:6px ridge; padding:10px;"> 
								    </div>
								</td>				
							</tr>
							<tr id="pos-table-header"  style="padding-left: 0px !important; height:20px !improtant;">					
								<td style="height:20px !important;">		
									<button id="save_button" style="width:95px !important; margin-left:40px;" class="buttons"><span><p  style="font-size:12px !important;">შენახვ.</p></span></button>
									<button id="cancel_button" class="buttons" style="width:87px !important;"><p style="font-size:12px !important;">გაუქმ.</p></button>
									<button id="print_button"  class="buttons" style="width:95px !important;"><p style="font-size:12px !important;">ბეჭდვა</p></button>							
									<button id="pay_button"    class="buttons" style="width: 140px !important; margin: 3px 0 15px 40px;" trans="";><p style="font-size:12px !important;">გადახდა</p></button><div id="transact_id" style="display:none;"> </div>	
									<button id="terminal_payment" class="buttons" style="margin:-15px 0 -2px 2px;width: 141px;"><p style="font-size:12px !important;">ტერმინალ.</p></button>
									<br />
									<table>
											<tr>
												<td style="height:20px !important;">						
														<div id="make_payment" style="float: left; margin-bottom: 0px;  margin-left:25px;">
															<div id="pay_box">
																<input type="text" value="0.00" id="sum-total-price3" size="10" style="font-size: 16px;" />
															</div>
														</div>
								
												</td>
												<td class="change" style="padding:10px; white-space:nowrap; overflow:visible;">
													<span style="font-size:20px;">ხურდა: <span id="change2" style="font-size:25px; font-weigth:bold;">0.00</span></span>
												</td>
										  </tr>
									</table>												
								</td>
							</tr>
					
					</table>	
					<table style="position:absolute; left:990px; top:550px;">
						<tr>
							<td>
								<button id="add_money" class="buttons" style="width:163px !important;"><p style="font-size:12px !important;">თანხის დამატება</p></button>
								<button id="take_money" class="buttons" style="width:150px !important;"><p style="font-size:12px !important;">თანხის გატანა</p></button>
	 						</td>
	 					</tr>
	 				</table>
			     </td>
			   </tr>
			   <tr>
					<td>
						<div id="sale_details" style="margin-left:10px;">
								<table id="sales_items">
									<tr>
										<td class="left" style="height: 40px !important;"><pre style="font-size: 16px; margin-top: 8px;">რაოდენობა:        <span id="prod-quantity">0</span> ც</pre></td>			
									</tr>
								</table>
								<table id="sales_items_total">
									<tr>
										<td class="left" style="height: 40px !important;"><pre style="font-size: 16px; margin-top: 10px;">ჯამი:                	 <span id="sum-price">0.00</span> ლ</pre></td>
									</tr>
								</table>
						</div>
					</td>	
			   </tr>
			</table>
			
		</div><input style="display: none;" type="text" id="trans_id_hidden" name ="trans_id_hidden" value=""/>
	</div>
</body>
</html>